import Mock from 'mockjs'

const adminList = []
const count = 100
const role_name = ['管理员', '风控员', '调解员', '财务', '宣传员']

for (let i = 0; i < count; i++) {
  adminList.push(Mock.mock({
    id: '@increment',
    account: '@cname',
    'phone|13000000000-17999999999': 1,
    email: '@email',
    'role_id': i % 5 + 1,
    'role_name': role_name[i % 5],
    'status|1': [0, 1] //0 正常，1 禁用
  }))
}

export default [
  {
    url: '/admins/list',
    type: 'get',
    response: config => {
      const { status, search, page = 1, limit = 20, order } = config.query

      let mockList = adminList.filter(item => {
        if (status && item.status !== Number(status)) return false
        if (search && item.phone !== Number(search) && item.uid !== Number(search)) return false
        return true
      })

      if (order === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 0,
        msg: 'ok',
        data: {
          total: mockList.length,
          page: page,
          limit: limit,
          list: pageList
        }
      }
    }
  },

  {
    url: '/admins/add',
    type: 'post',
    response: _ => {
      return {
        code: 0,
        data: 'success'
      }
    }
  },

  {
    url: '/admins/edit',
    type: 'post',
    response: _ => {
      return {
        code: 0,
        data: 'success'
      }
    }
  },

  {
    url: '/admins/change-status',
    type: 'post',
    response: _ => {
      return {
        code: 0,
        data: 'success'
      }
    }
  },

  {
    url: '/admins/reset-password',
    type: 'post',
    response: _ => {
      return {
        code: 0,
        data: 'success'
      }
    }
  }
]

